<?php
/**
 * Created by PhpStorm.
 * Author: 芸签cms www.yunqiancms.com
 * User: sun
 * Date: 2022/6/30
 * Time: 10:55 AM
 */
namespace app\common\models;

class ThemeFileConfigLog extends BaseModel
{
    public $table = 'yq_theme_file_config_log';
    public $timestamps = true;
    protected $guarded = [''];

    const TYPE_PREVIEW = 0;//类型预览
    const TYPE_SAVE = 1;//类型保存


    public static function getLastByThemeFile($themeFileId,$type=0){
        $res = self::site()->select()
            ->where('theme_file_id',$themeFileId)
            ->where('type',$type)
            ->orderBy('id','desc')
            ->first();
        if(!$res){
            //保存记录不存在，从ThemeFile中取
            $themeFileInfo = ThemeFile::find($themeFileId);
            if($themeFileInfo){
                $res['id'] = 0;
                $res['theme_file_id'] = $themeFileId;
                $res['type'] = $type;
                $res['page_info'] = $themeFileInfo['page_info'];
                $res['configs'] = $themeFileInfo['configs'];
            }
        }
        return $res;
    }
}